#include "cppTutorConstCorrectness.h"

#include <iostream>

using namespace std;

CcppTutorConstCorrectness :: CcppTutorConstCorrectness () : m_nValue (0)
{
}

CcppTutorConstCorrectness :: CcppTutorConstCorrectness (int nValue) : m_nValue (nValue)
{
}

CcppTutorConstCorrectness :: ~CcppTutorConstCorrectness()
{
}

void CcppTutorConstCorrectness :: m_Change ()
{
    ++ m_nValue;
}

void CcppTutorConstCorrectness :: m_Display ()
{
    cout << m_nValue << endl;
}

void CcppTutorConstCorrectness :: constPointer () {
    cout << "Const Pointer" << endl;
    int nValue = 100;
    int nAnotherValue = 200;
    // put a const between a asterisk and the pointer name to create a const pointer and assign some value immediately
    int* const pnPtr = &nValue;
    cout << *pnPtr << endl;
    cout << "change the value being pointed to via dereferencing the pointer" << endl;
    *pnPtr = 300;
    cout << *pnPtr << endl;
}

void CcppTutorConstCorrectness :: PointerToConst () {
    cout << "Pointer to Const" << endl;
    int nValue = 100;
    int nAnotherValue = 200;

    // creata a pointer to a const put the const before the data type, as compared to 'const pointer' no need to assign a value immediately
    //const int* pnPtr = &nValue;
    const int* pnPtr;
    pnPtr = &nValue;
    cout << *pnPtr << endl;
    cout << "pointer to a const value is a non-const pointer, the pointer can be redirected to point at other values" << endl;
    pnPtr = &nAnotherValue;
    cout << *pnPtr << endl;
}

void CcppTutorConstCorrectness :: constPointerToConstValue () {
    int nValue = 100;
    int nAnotherValue = 200;
    const int* const pnPtr = &nValue;
    //pnPtr = &nAnotherValue;
    //*pnPtr = 300;
}
